package com.check.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.check.pojo.MarkData;
import com.check.pojo.PageObject;
import com.check.pojo.Pcwh;
import com.check.service.MarkDataService;
import com.check.service.PcwhService;

@Controller
public class MarkMemoController extends BaseController{

	@Autowired
	@Qualifier("pcwhService")
	private PcwhService pcwhService;
	
	@Autowired
	@Qualifier("markDataService")
	private MarkDataService markDataService;
	
	@RequestMapping("markMemo.do")
	public ModelAndView markMemo(HttpServletRequest request,HttpServletResponse response){
		List<Pcwh> pcwhList = pcwhService.findAllPcwh();
		return new ModelAndView("page/markMemo/markMemo")
				.addObject("path",request.getContextPath())
				.addObject("pcwhList",pcwhList);
	}
	
	@RequestMapping("markMemoResult.do")
	public ModelAndView markMemoResult(HttpServletRequest request,HttpServletResponse response,
			@ModelAttribute("markData")MarkData markData,@ModelAttribute("pageObject")PageObject pageObject){
		if(pageObject.getCurrent()==0){
			pageObject.setCurrent(1);
		}
		
		if(markData.getCheckId()==null){
			markData.setCheckId("");
		}
		if(markData.getCheckYear()==null){
			markData.setCheckYear("");
		}
		
		saveSysLog(RE_MARKMEMO, LOG_QUERY, request);
		List<MarkData> markDataList=markDataService.findAllMarkDataMemo(markData,pageObject);
		pageObject.setTotal(markDataService.findAllMarkDataMemoCount(markData));
		pageObject.setUrl("markMemoResult.do?checkYear="+markData.getCheckYear()+"&expType="+markData.getExpType()+"&checkId="+markData.getCheckId()+"&");

		return new ModelAndView("page/markMemo/markMemoResult")
				.addObject("path",request.getContextPath())
				.addObject("page",pageObject.toPage())
				.addObject("markDataList",markDataList);
	}
}
